(function() {

    angular.module('BlurAdmin.pages.feedback')
        .controller('FeedbackCtrl', FeedbackCtrl);

    function FeedbackCtrl($scope, $openModal, $myconfig, $datepicker, $http, $mydialog) {
        console.log(123123123123);
        $scope.open = $openModal; //创建实例化对象
        function fn(val) { //关闭模态框方法
            $scope.myopen.opt_close = val;
        }
        $scope.myopen = function(page, size) { //打开模态框
            $scope.open.newOpen(page, size, $scope, fn, 'static');
        }
        $scope.myopen2 = function(page, size) { //打开模态框 ,可关闭
            $scope.open.newOpen(page, size, $scope, fn);
        }



        //日期插件
        $scope.format = "yyyy/MM/dd";
        $scope.altInputFormats = ['yyyy-MM-dd-HH'];
        $scope.dat = {
            dat1: $datepicker.dataNew(),
            dat2: $datepicker.dataNew(),
            dat3: $datepicker.dataNew(),
            dat4: $datepicker.dataNew(),
        };
        $scope.dat.dat1.date_ = null;
        $scope.dat.dat2.date_ = null;
        $scope.dat.dat3.date_ = null;
        $scope.dat.dat4.date_ = null;
        //分页
        $scope.feedback_search_data = {
            "limit": 10,
            "page": 1,
            "content": "",
            "username": "",
            "mobile": "",
            "start_feedbacktime": null,
            "end_feedbacktime": null,
            "start_processtime": null,
            "end_processtime": null,
            "status": 'all'
        };

        //点击分页事件
        $scope.maxSize = 5;
        // $scope.bigTotalItems = 50;
        $scope.bigCurrentPage = 1;
        $scope.pageChanged = function(val) {
            console.log(val);
            var Page_num = val //选中的页面数
            $scope.feedback_search_data.page = val;
            Search_list();
        };
        var search_opt = {}

        $scope.Search = function() { //点击搜索，进行条件赋值
            search_opt = {};
            var opt2 = $scope.feedback_search_data;
            //赋值时间
            var data1 = document.getElementById("dat1") ? document.getElementById("dat1").value : null;
            var data2 = document.getElementById("dat2") ? document.getElementById("dat2").value : null;
            var data3 = document.getElementById("dat3") ? document.getElementById("dat3").value : null;
            var data4 = document.getElementById("dat4") ? document.getElementById("dat4").value : null;

            opt2.start_feedbacktime = data1;
            opt2.end_feedbacktime = data2;
            opt2.start_processtime = data3;
            opt2.end_processtime = data4;

            opt2.content && (search_opt.content = opt2.content);
            opt2.username && (search_opt.username = opt2.username);
            opt2.mobile && (search_opt.mobile = opt2.mobile);
            opt2.start_feedbacktime && (search_opt.start_feedbacktime = opt2.start_feedbacktime);
            opt2.end_feedbacktime && (search_opt.end_feedbacktime = opt2.end_feedbacktime);
            opt2.start_processtime && (search_opt.start_processtime = opt2.start_processtime);
            opt2.end_processtime && (search_opt.end_processtime = opt2.end_processtime);
            opt2.status && (opt2.status != 'all') && (search_opt.status = opt2.status);
            !opt2.status && (search_opt.status = opt2.status);
            Search_count_b();
        }

        function Search_count_b() { //反馈列表数据统计
            $http.get($myconfig.api.feedback_count_b, { params: search_opt }).then(function(res) {
                $scope.bigTotalItems = res.data.data;
                Search_list();
            });
        }
        $scope.Search_list_data = null;

        function Search_list() { //获取列表信息
            search_opt.limit = $scope.feedback_search_data.limit;
            search_opt.page = $scope.feedback_search_data.page;

            $http.get($myconfig.api.feedback_list_b, { params: search_opt }).then(function(res) {
                if (res.data.success) {
                    for (var i = 0; i < res.data.data.length; i++) { //添加条数属性
                        res.data.data[i].num = (($scope.feedback_search_data.page - 1) * $scope.feedback_search_data.limit) + i + 1;
                    }
                    $scope.Search_list_data = res.data.data;
                }

                console.log($scope.Search_list_data);
            });
        }
        $scope.Search(); //初始加载信息

        //消息反馈

        //打开输入框
        $scope.feedback_id = null;
        $scope.open_text = function(id) {
            $scope.feedback_id = id;
            $scope.myopen('app/pages/feedbackM/open_text.html', 'lg')
        }


        $scope.update_feedback = function() {

            var val = $('#textarea01').val();
            if (!val) {
                return $mydialog.fail('请输入反馈内容')
            }
            $http.post($myconfig.api.feedback_update_feedback, {
                "feedback_id": $scope.feedback_id,
                "processdesc": val
            }).then(function(res) {
                console.log(res);
                if (res.data.success) {
                    $scope.Search(); //重新加载列表
                    $mydialog.success('处理成功');
                    $scope.myopen.opt_close();
                } else {
                    $mydialog.fail('处理失败')
                }
            })
        }



    }
})();